package com.edu.system.service.impl;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.edu.system.domain.TRechargeRecord;
import com.edu.system.mapper.TRechargeRecordMapper;
import com.edu.system.service.ITRechargeRecordService;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 充值记录Service业务层处理
 *
 * @author xxxx
 * @date 2023-12-22
 */
@Service
public class TRechargeRecordServiceImpl implements ITRechargeRecordService {
    @Autowired
    private TRechargeRecordMapper tRechargeRecordMapper;

    /**
     * 查询充值记录
     *
     * @param id 充值记录主键
     * @return 充值记录
     */
    @Override
    public TRechargeRecord selectTRechargeRecordById(Long id) {
        TRechargeRecord tRechargeRecord = tRechargeRecordMapper.selectTRechargeRecordById(id);
        return tRechargeRecord;
    }

    /**
     * 查询充值记录列表
     *
     * @param tRechargeRecord 充值记录
     * @return 充值记录
     */
    @Override
    public List<TRechargeRecord> selectTRechargeRecordList(TRechargeRecord tRechargeRecord) {
        return tRechargeRecordMapper.selectTRechargeRecordList(tRechargeRecord);
    }

    /**
     * 新增充值记录
     *
     * @param r 充值记录
     * @return 结果
     */
    @Override
    public int insertTRechargeRecord(TRechargeRecord r) {
        if (StrUtil.isBlank(r.getBillNo())) {
            r.setBillNo(this.genBillNo());
        }
        return tRechargeRecordMapper.insertTRechargeRecord(r);
    }

    private String genBillNo() {
        return "cz" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_FORMAT) + RandomUtil.randomNumbers(4);
    }

    /**
     * 批量删除充值记录
     *
     * @param ids 需要删除的充值记录主键
     * @return 结果
     */
    @Override
    public int deleteTRechargeRecordByIds(Long[] ids) {
        return tRechargeRecordMapper.deleteTRechargeRecordByIds(ids);
    }

}
